#!/bin/bash

##MemTotal:   kB MemFree:   kB

MemTotal=$(cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}')
MemFree=$(cat /proc/meminfo | grep 'MemFree' | awk '{print $2}')
Mem_Rate=`expr "scale=2; 100 - ($MemFree / $MemTotal * 100)" |bc -l`
Mem_Use=`expr "scale=2; ($MemTotal - $MemFree) / 1024" |bc -l`

exitstatus=0

if [ $Mem_Rate \> 99 ];
then
status=CRITICAL
exitstatus=2

elif [ $Mem_Rate \< 99 ];
      then
        status=OK
        exitstatus=0

elif [ $Mem_Rate \> 95 ];
      then
          status=WARNING
          exitstatus=1
      else
          status=OK
          exitstatus=0
fi

echo "System memory free : ($MemFree KB out of $MemTotal KB) [$status]"
echo "| Mem_data=$Mem_Use"Mb";5600;7200;0;8000"

exit $exitstatus
